#ifndef __RESFILELOOKUPDATAMAN_H__
#define __RESFILELOOKUPDATAMAN_H__

#include "ResFile.h"

typedef std::vector<CCryNameTSCRC> TResDirNames;

struct SSharedIdent
{
  CCryNameTSCRC m_Name;
  uint32 m_CRC;
  SSharedIdent() { m_CRC = 0; }
  SSharedIdent(CCryNameTSCRC Name, uint32 CRC)
  {
    m_Name = Name;
    m_CRC = CRC;
  }
  AUTO_STRUCT_INFO
};
struct SResFileLookupDataDisk
{
	int m_NumOfFilesUnique;
	int m_NumOfFilesRef;
	uint32 m_OffsetDir;
	uint32 m_CRC32;
  uint16 m_CacheMajorVer;
  uint16 m_CacheMinorVer;
	
  uint32 m_nNumSharedIdents;

  SResFileLookupDataDisk() {}
  SResFileLookupDataDisk(const struct SResFileLookupData& inLookup);

	AUTO_STRUCT_INFO
};
struct SResFileLookupData
{
  int m_NumOfFilesUnique;
  int m_NumOfFilesRef;
  uint32 m_OffsetDir;
  uint32 m_CRC32;
  uint16 m_CacheMajorVer;
  uint16 m_CacheMinorVer;

  SResFileLookupData() {}
  SResFileLookupData(const SResFileLookupDataDisk& inLookup)
  {
    m_NumOfFilesUnique = inLookup.m_NumOfFilesUnique;
    m_NumOfFilesRef = inLookup.m_NumOfFilesRef;
    m_OffsetDir = inLookup.m_OffsetDir;
    m_CRC32 = inLookup.m_CRC32;
    m_CacheMajorVer = inLookup.m_CacheMajorVer;
    m_CacheMinorVer = inLookup.m_CacheMinorVer;
  }

#ifdef USE_PARTIAL_ACTIVATION
  bool m_ContainsResDir;

  TResDirNames m_resdirlookup;
  ResDir m_resdir;

  unsigned int GetDirOffset(const CCryNameTSCRC& dirEntryName) const;
#endif
  std::vector<SSharedIdent> m_SharedIdents;
};

struct SCFXLookupData
{
  uint32 m_CRC32;
  SCFXLookupData() {}
  AUTO_STRUCT_INFO
};

#define MAX_DIR_BUFFER_SIZE 300000

typedef std::map<CCryNameTSCRC, SResFileLookupData> TFileResDirDataMap;
typedef std::map<CCryNameTSCRC, SCFXLookupData> TFileCFXDataMap;

class CResFile;

struct SVersionInfo
{
	SVersionInfo() : m_ResVersion(0)
	{}

	int m_ResVersion;
	char m_szCacheVer[16];

	AUTO_STRUCT_INFO
};

class CResFileLookupDataMan
{
public:
	CResFileLookupDataMan();
	~CResFileLookupDataMan();

	void Clear();
  void Flush();

  CCryNameTSCRC AdjustName(const char *szName);
	int GetResVersion() const { return m_VersionInfo.m_ResVersion; }

	bool LoadData(const char* acFilename, bool bSwapEndianRead);
	void SaveData(const char* acFilename, bool bSwapEndianWrite) const;

	void AddData(const CResFile* pResFile, uint32 CRC);
	void AddDataCFX(const char *szPath, uint32 CRC);
	void RemoveData(uint32 CRC);

	SResFileLookupData* GetData(const CCryNameTSCRC& name);
  SCFXLookupData* GetDataCFX(const char *szPath);
  void MarkDirty(bool bDirty) { m_bDirty = bDirty; }


protected:
	
  string m_Path;
	SVersionInfo m_VersionInfo;
	TFileResDirDataMap m_Data;
  TFileCFXDataMap m_CFXData;
  bool m_bDirty;
	unsigned int m_TotalDirStored;
};

#endif //  __RESFILELOOKUPDATAMAN_H__
